package com.zhangh.summer.admin.support.boot.filter;

import com.zhangh.summer.admin.support.boot.common.ApplicationConfig;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

/**
 * @description: TODO
 * @author: zhanghui  zhanghlucky@163.com
 * @create: 2021-06-08 22:59
 **/
public class ErpFilter implements TypeFilter {

    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
            throws IOException {
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        String className = classMetadata.getClassName();

        for (Class cls: ApplicationConfig.config().getExclusionClass()) {
            if (className.equals(cls.getName())) {
                return true;
            }
        }
        for (String pack:ApplicationConfig.config().getExclusionPackage()) {
            if (className.contains(pack)) {
                return true;
            }
        }
        return false;
    }

}
